import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-04-13
 * Time: 23:26
 */
public class test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        LinkedList<Integer> linkedList = new LinkedList<>();
        int num = 0;
        int n =scanner.nextInt();
        for (int i = 1; i <=n; i++) {
            linkedList.add(i);

        }
        while (linkedList.size()>1) {
            for (int i = 0; i < n; i++) {
                if (num % 3 == 0) {
                    linkedList.remove(i);
                    n--;
                    i--;
                }
                num += linkedList.get(i);


            }
        }
        System.out.println(linkedList.get(0));
    }
}
